package com.lyl.aliyunossservice.controller;

import com.lyl.aliyunossservice.service.FileService;
import com.lyl.commonutils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@Api(description="阿里云文件管理")
@CrossOrigin //跨域
@RestController
@RequestMapping("/oss/file")
public class FileUploadController {
    @Autowired
    private FileService fileService;

    /**
     * 讲师头像上传
     *
     * @param file
     */
    @ApiOperation(value = "上传直播课程封面")
    @PostMapping("livecover")
    public R liveCover(
            @ApiParam(name = "file", value = "文件", required = true)
            @RequestParam("file") MultipartFile file) {
        String uploadUrl = fileService.uploadFileLiveCover(file);        //返回r对象
        return R.ok().message("文件上传成功").data("url", uploadUrl);

    }

    /**
     * 讲师头像上传
     *
     * @param file
     */
    @ApiOperation(value = "讲师头像上传")
    @PostMapping("upload")
    public R upload(
            @ApiParam(name = "avatar", value = "文件", required = true)
            @RequestParam("avatar") MultipartFile file) {
        String uploadUrl = fileService.uploadFileAvatar(file);        //返回r对象
        return R.ok().message("文件上传成功").data("url", uploadUrl);

    }
    @ApiOperation(value = "课程封面上传")
    @PostMapping("coursecover")
    public R coursecover(
            @ApiParam(name = "cover", value = "封面", required = true)
            @RequestParam("file") MultipartFile file) {
        String uploadUrl = fileService.uploadFileCover(file);        //返回r对象
        return R.ok().message("文件上传成功").data("url", uploadUrl);

    }

    @ApiOperation(value = "首页图片上传")
    @PostMapping("bannerupload")
    public R bannerupload(
            @ApiParam(name = "banner", value = "banner", required = true)
            @RequestParam("file") MultipartFile file) {
        String uploadUrl = fileService.uploadFileBanner(file);        //返回r对象
        return R.ok().message("文件上传成功").data("url", uploadUrl);

    }


    @ApiOperation(value = "客户简历上传")
    @PostMapping("userresumeupload")
    public R userresumeupload(
            @ApiParam(name = "resume", value = "resume", required = true)
            @RequestParam("file") MultipartFile file) {
        String uploadUrl = fileService.uploadFileUserResume(file);        //返回r对象
        return R.ok().message("文件上传成功").data("url", uploadUrl);

    }

    @ApiOperation(value = "简历模板上传")
    @PostMapping("resumemodelupload")
    public R resumemodelupload(
            @ApiParam(name = "resume", value = "resume", required = true)
            @RequestParam("file") MultipartFile file) {
        String uploadUrl = fileService.uploadFileResumeMode(file);        //返回r对象
        return R.ok().message("文件上传成功").data("url", uploadUrl);

    }

}
